package com.demo.controller;

import com.demo.domain.ResponseResult;
import com.demo.domain.User;
import com.demo.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
public class LoginController {

    @Autowired
    private LoginService loginService;

    //登录
    @PostMapping("/user/login")
    public ResponseResult<User> login(@RequestBody User user) {
        try {
            return loginService.login(user);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            return new ResponseResult(500, ex.getMessage());
        }
    }

    //退出登录
    @RequestMapping("/user/logout")
    public ResponseResult logout() {
        try {
            return loginService.logout();
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            return new ResponseResult(500, ex.getMessage());
        }
    }
}
